package com.example.music.shape

class ShapeManager constructor(private val shapes: String) {
    companion object {
        private const val path = "com.example.music.shape."
    }

    private val shapeList: List<IShape> by lazy {
        kotlin.runCatching {
            shapes.split(",").mapNotNull {
                val clazz = Class.forName("$path$it")
                clazz.newInstance() as? IShape
            }
        }.onFailure {
            println("$it")
        }.getOrDefault(listOf())
    }

    fun getArea() {
        var area: Double
        shapeList.forEach {
            area = it.area(1.0)
            println("area of $it = $area")
        }
    }
}